<!-- 库存列表 -->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" v-show="showSearch" :inline="true" label-width="72px">
      <el-form-item label="耗材编号" prop="goods_id">
        <el-input v-model="queryParams.goods_id" placeholder="请输入耗材编号" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="耗材名称" prop="goods_name">
        <el-input v-model="queryParams.goods_name" placeholder="请输入耗材名称" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 表格数据 -->
    <el-table v-loading="loading" :data="goodsList" border>
      <el-table-column label="耗材编号" prop="goods_id" />
      <el-table-column label="耗材名称" prop="goods_name" />
      <el-table-column label="库存数量" prop="qty" />
      <el-table-column label="可用库存" prop="aval_qty" />
      <el-table-column label="锁库数量" prop="lock_qty" />
      <el-table-column label="操作人" prop="update_user_name" />
      <el-table-column label="操作日期" prop="update_date" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.page_num"
      v-model:limit="queryParams.page_size"
      @pagination="getList"
    />
  </div>
</template>

<script setup name="InvertoryList">
import { getInvList } from "@/api/inventory/list";
const { proxy } = getCurrentInstance();
const showSearch = ref(true);
const loading = ref(false);
const queryParams = ref({
  page_num: 1,
  page_size: 10,
  goods_name: "",
  goods_id: "",
  status: ""
});
const goodsList = ref([]);
const total = ref(0);

getList();

/** 查询列表 */
function getList() {
  loading.value = true;
  getInvList(queryParams.value)
    .then((res) => {
      const data = res.data;
      goodsList.value = data.list;
      total.value = data.total;
      loading.value = false;
    })
    .catch(() => {
      loading.value = false;
    });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.page_num = 1;
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}
</script>
